import upload from '@/utils/upload'
import request from '@/utils/request'

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/admin-api/system/user/profile/update-password',
    method: 'put',
    data: data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/admin-api/system/user/profile/get',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/admin-api/system/user/profile/update',
    method: 'put',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  // 获取当前日期,格式化为 YYYY-MM-DD
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const dateFolder = `${year}-${month}-${day}`
  
  return upload({
    url: '/admin-api/infra/file/upload',
    name: data.name,
    filePath: data.filePath,
    formData: {
      directory: `home/${dateFolder}` // 上传到 /www/wwwroot/home/2025-11-09/
    }
  })
}
